diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2020-12-25 13:47:44 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2020-12-25 13:47:44 +0000 |
commit | 8f73ecc72c45997ce262149bed3b2bfd2ce9554b (patch) | |
tree | 932a669f961502edf6a2c6e3e5e872ebaf3d4fe7 | |
parent | 0ddae2e43bde351e699797b713fdfd0c4d71688b (diff) |
Switch to scapy with python 3.
-rw-r--r-- | regress/sys/netinet6/rip6cksum/LICENSE | 28 | ||||
-rw-r--r-- | regress/sys/netinet6/rip6cksum/Makefile | 13 | ||||
-rwxr-xr-x | regress/sys/netinet6/rip6cksum/sendrecv.py | 46 |
3 files changed, 42 insertions, 45 deletions
diff --git a/regress/sys/netinet6/rip6cksum/LICENSE b/regress/sys/netinet6/rip6cksum/LICENSE index 897cd3e6996..bc9ef0e40f8 100644 --- a/regress/sys/netinet6/rip6cksum/LICENSE +++ b/regress/sys/netinet6/rip6cksum/LICENSE @@ -1,15 +1,13 @@ -/* - * Copyright (c) 2019 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 - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ +Copyright (c) 2019-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 +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/regress/sys/netinet6/rip6cksum/Makefile b/regress/sys/netinet6/rip6cksum/Makefile index 954cec8b815..63534cf71f3 100644 --- a/regress/sys/netinet6/rip6cksum/Makefile +++ b/regress/sys/netinet6/rip6cksum/Makefile @@ -1,20 +1,21 @@ -# $OpenBSD: Makefile,v 1.4 2020/12/17 00:51:13 bluhm Exp $ +# $OpenBSD: Makefile,v 1.5 2020/12/25 13:47:43 bluhm Exp $ # The following ports must be installed: # -# python-2.7 interpreted object-oriented programming language # scapy powerful interactive packet manipulation in python -.if ! exists(/usr/local/bin/python2.7) || ! exists(/usr/local/bin/scapy) +.if ! exists(/usr/local/bin/scapy-3) regress: - @echo Install python and the scapy module for additional tests. + @echo Install scapy package to run this regress. @echo SKIPPED .endif PROG = rip6cksum WARNINGS = yes -PYTHON = python2.7 -u ${.CURDIR}/ +PYTHON = python3 -u ${.CURDIR}/ + +REGRESS_SETUP += ${PROG} REGRESS_TARGETS += run-error-negative run-error-negative: @@ -116,6 +117,4 @@ run-ckoff-2-long: ${SUDO} ./rip6cksum -c 2 -r 5 -s 5 -w -- \ ${PYTHON}sendrecv.py -c 2 -s 5 -${REGRESS_TARGETS}: ${PROG} - .include <bsd.regress.mk> diff --git a/regress/sys/netinet6/rip6cksum/sendrecv.py b/regress/sys/netinet6/rip6cksum/sendrecv.py index 70e4499e52d..54192dcb48f 100755 --- a/regress/sys/netinet6/rip6cksum/sendrecv.py +++ b/regress/sys/netinet6/rip6cksum/sendrecv.py @@ -1,5 +1,5 @@ -#!/usr/local/bin/python2.7 -# $OpenBSD: sendrecv.py,v 1.2 2019/05/10 14:45:00 bluhm Exp $ +#!/usr/local/bin/python3 +# $OpenBSD: sendrecv.py,v 1.3 2020/12/25 13:47:43 bluhm Exp $ import os from scapy.all import * @@ -7,12 +7,12 @@ from struct import pack import getopt, sys def usage(): - print "sendrecv [-hi] [-c ckoff] [-r recvsz] [-s sendsz]" - print " -c ckoff set checksum offset within payload" - print " -h help, show usage" - print " -i expect icmp6 error message as response" - print " -r recvsz expected payload size" - print " -s sendsz set payload size" + print("sendrecv [-hi] [-c ckoff] [-r recvsz] [-s sendsz]") + print(" -c ckoff set checksum offset within payload") + print(" -h help, show usage") + print(" -i expect icmp6 error message as response") + print(" -r recvsz expected payload size") + print(" -s sendsz set payload size") exit(1) opts, args = getopt.getopt(sys.argv[1:], "c:hir:s:") @@ -35,16 +35,16 @@ for o, a in opts: else: usage() -payload = ""; +payload = b""; if sendsz is not None: for i in range(sendsz): - payload += chr(i & 0xff) - print "payload length is", len(payload) + payload += pack('B', i) + print("payload length is", len(payload)) if ckoff is not None: payload = payload[:ckoff] + pack("xx") + payload[ckoff+2:] cksum = in6_chksum(255, ip, payload) - print "calculated checksum is", cksum + print("calculated checksum is", cksum) payload = payload[:ckoff] + pack("!H", cksum) + payload[ckoff+2:] req=ip/payload @@ -58,37 +58,37 @@ else: filter="proto 255" if recvsz is not None: filter += (" and len = %d" % (4 + 40 + recvsz)) -print "filter", filter +print("filter", filter) ans=sr(req, iface="lo0", filter=filter, timeout=10) -print ans +print(ans) res=ans[0][0][1] res.show() -print "response protocol next header is", res.nh +print("response protocol next header is", res.nh) if icmp: if res.nh != 58: - print "response wrong protocol, expected icmp6" + print("response wrong protocol, expected icmp6") exit(1) - print "response icmp6 type is", res.payload.type + print("response icmp6 type is", res.payload.type) if res.payload.type != 4: - print "response wrong icmp6 type, expected parameter problem" + print("response wrong icmp6 type, expected parameter problem") exit(1) exit(0) if res.nh != 255: - print "response with wrong protocol, expected 255, got" + print("response with wrong protocol, expected 255, got") exit(1) cksum = in6_chksum(255, res, res.payload.load) -print "received checksum is", cksum +print("received checksum is", cksum) if ckoff is not None and cksum != 0: - print "received invalid checksum", cksum + print("received invalid checksum", cksum) exit(1) -print "received payload length is", len(res.payload.load) +print("received payload length is", len(res.payload.load)) if recvsz is not None: if len(res.payload.load) != recvsz: - print "wrong payload length, expected", recvsz + print("wrong payload length, expected", recvsz) exit(1) exit(0) |