diff --git a/fix_s390x_tests.patch b/fix_s390x_tests.patch new file mode 100644 index 0000000..2962826 --- /dev/null +++ b/fix_s390x_tests.patch @@ -0,0 +1,246 @@ +From 4ce0b897e60a67fec4b590af058fd702563d79c5 Mon Sep 17 00:00:00 2001 +From: Oscar +Date: Sun, 27 Dec 2020 11:18:50 -0800 +Subject: [PATCH] Fix #505 and other big endian arch bugfixes (#510) + +* issue #505: fix inet checksum calculation +* issue #505: fix pcapng unit test +* issue #505: fix ieee80211 +* issue #505: radiotap fix for big endian systems +--- + dpkt/compat.py | 12 ++++++++++-- + dpkt/dpkt.py | 24 +++++++++++++----------- + dpkt/ieee80211.py | 21 +++++++++++---------- + dpkt/pcapng.py | 8 +++++++- + dpkt/radiotap.py | 5 ++--- + 5 files changed, 43 insertions(+), 27 deletions(-) + +--- a/dpkt/compat.py ++++ b/dpkt/compat.py +@@ -1,5 +1,6 @@ + from __future__ import absolute_import + ++from struct import pack, unpack + import sys + + if sys.version_info < (3,): +@@ -19,9 +20,9 @@ try: + except ImportError: + from io import StringIO + +-try: ++try: + from BytesIO import BytesIO +-except ImportError: ++except ImportError: + from io import BytesIO + + if sys.version_info < (3,): +@@ -37,3 +38,10 @@ else: + + # python3 will return an int if you round to 0 decimal places + intround = round ++ ++ ++def ntole(v): ++ """convert a 2-byte word from the network byte order (big endian) to little endian; ++ replaces socket.ntohs() to work on both little and big endian architectures ++ """ ++ return unpack('') + +@@ -146,7 +144,7 @@ class Packet(_MetaPacket("Temp", (object + + def __str__(self): + return str(self.__bytes__()) +- ++ + def __bytes__(self): + return self.pack_hdr() + bytes(self.data) + +@@ -200,16 +198,17 @@ def hexdump(buf, length=16): + def in_cksum_add(s, buf): + n = len(buf) + cnt = (n // 2) * 2 +- a = array.array('H', buf[:cnt]) ++ a = struct.unpack('<{}H'.format(n // 2), buf[:cnt]) # unpack as little endian words ++ res = s + sum(a) + if cnt != n: +- a.append(compat_ord(buf[-1])) +- return s + sum(a) ++ res += compat_ord(buf[-1]) ++ return res + + + def in_cksum_done(s): + s = (s >> 16) + (s & 0xffff) + s += (s >> 16) +- return socket.ntohs(~s & 0xffff) ++ return ntole(~s & 0xffff) + + + def in_cksum(buf): +@@ -222,5 +221,6 @@ def test_utils(): + __hd = ' 0000: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e ...............' + h = hexdump(__buf) + assert (h == __hd) ++ assert in_cksum_add(0, __buf) == 12600 # endianness + c = in_cksum(__buf) + assert (c == 51150) +--- a/dpkt/ieee80211.py ++++ b/dpkt/ieee80211.py +@@ -8,6 +8,7 @@ import socket + import struct + + from . import dpkt ++from .compat import ntole + + # Frame Types + MGMT_TYPE = 0 +@@ -329,7 +330,7 @@ class IEEE80211(dpkt.Packet): + + # Strip off the FCS field + if self.fcs_present: +- self.fcs = struct.unpack('I', self.data[-1 * FCS_LENGTH:])[0] ++ self.fcs = struct.unpack(' + +- Rename skip_s390x_tests.patch to fix_s390x_tests.patch (from the + upstream commit 4ce0b897e60a), which seems to fix the problem. + ------------------------------------------------------------------- Mon Dec 14 22:51:23 UTC 2020 - Matej Cepl diff --git a/python-dpkt.spec b/python-dpkt.spec index 62e4ade..705c4fe 100644 --- a/python-dpkt.spec +++ b/python-dpkt.spec @@ -1,7 +1,7 @@ # # spec file for package python-dpkt # -# Copyright (c) 2020 SUSE LLC +# Copyright (c) 2021 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -25,9 +25,9 @@ License: BSD-3-Clause Group: Development/Libraries/Python URL: https://github.com/kbandla/dpkt Source: https://github.com/kbandla/dpkt/archive/v%{version}.tar.gz -# PATCH-FIX-UPSTREAM skip_s390x_tests.patch gh#kbandla/dpkt#505 mcepl@suse.com +# PATCH-FIX-UPSTREAM fix_s390x_tests.patch gh#kbandla/dpkt#505 mcepl@suse.com # Skip failing tests on s390x arch -Patch0: skip_s390x_tests.patch +Patch0: fix_s390x_tests.patch BuildRequires: %{python_module mock} BuildRequires: %{python_module pytest} BuildRequires: %{python_module setuptools} diff --git a/skip_s390x_tests.patch b/skip_s390x_tests.patch deleted file mode 100644 index 7e8adcb..0000000 --- a/skip_s390x_tests.patch +++ /dev/null @@ -1,122 +0,0 @@ ---- - dpkt/dpkt.py | 10 +++++++--- - dpkt/ieee80211.py | 21 ++++++++++++++++++++- - dpkt/pcapng.py | 6 ++++++ - 3 files changed, 33 insertions(+), 4 deletions(-) - ---- a/dpkt/dpkt.py -+++ b/dpkt/dpkt.py -@@ -1,13 +1,15 @@ - # $Id: dpkt.py 43 2007-08-02 22:42:59Z jon.oberheide $ - # -*- coding: utf-8 -*- - """Simple packet creation and parsing.""" --from __future__ import absolute_import -+from __future__ import absolute_import - - import copy - import socket - import struct - import array - from functools import partial -+from platform import processor -+from unittest import SkipTest - - from .compat import compat_ord, compat_izip, iteritems - -@@ -48,7 +50,7 @@ class Packet(_MetaPacket("Temp", (object - """Base packet class, with metaclass magic to generate members from self.__hdr__. - - Attributes: -- __hdr__: Packet header should be defined as a list of -+ __hdr__: Packet header should be defined as a list of - (name, structfmt, default) tuples. - __byte_order__: Byte order, can be set to override the default ('>') - -@@ -146,7 +148,7 @@ class Packet(_MetaPacket("Temp", (object - - def __str__(self): - return str(self.__bytes__()) -- -+ - def __bytes__(self): - return self.pack_hdr() + bytes(self.data) - -@@ -218,6 +220,8 @@ def in_cksum(buf): - - - def test_utils(): -+ if 's390x' in processor(): -+ raise SkipTest("Test fails on s390x, gh#kbandla/dpkt#505") - __buf = b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e' - __hd = ' 0000: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e ...............' - h = hexdump(__buf) ---- a/dpkt/ieee80211.py -+++ b/dpkt/ieee80211.py -@@ -6,6 +6,8 @@ from __future__ import absolute_import - - import socket - import struct -+from platform import processor -+from unittest import SkipTest - - from . import dpkt - -@@ -672,7 +674,8 @@ def test_80211_beacon(): - assert ieee.mgmt.dst == b'\xff\xff\xff\xff\xff\xff' - assert ieee.mgmt.src == b'\x00\x26\xcb\x18\x6a\x30' - assert ieee.beacon.capability == 0x3104 -- assert ieee.capability.privacy == 1 -+ if 's390x' not in processor(): -+ assert ieee.capability.privacy == 1 - assert ieee.ssid.data == b'CAEN' - assert ieee.rate.data == b'\x82\x84\x8b\x0c\x12\x96\x18\x24' - assert ieee.ds.data == b'\x01' -@@ -746,6 +749,8 @@ def test_data_ds(): - assert ieee.data_frame.dst == b'\x00\x02\x44\xac\x27\x70' - - def test_compressed_block_ack(): -+ if 's390x' in processor(): -+ raise SkipTest("Test fails on s390x, gh#kbandla/dpkt#505") - s = b'\x94\x00\x00\x00\x34\xc0\x59\xd6\x3f\x62\xb4\x75\x0e\x46\x83\xc1\x05\x50\x80\xee\x03\x00\x00\x00\x00\x00\x00\x00\xa2\xe4\x98\x45' - ieee = IEEE80211(s, fcs=True) - assert ieee.type == CTL_TYPE -@@ -758,6 +763,8 @@ def test_compressed_block_ack(): - assert ieee.back.tid == 5 - - def test_action_block_ack_request(): -+ if 's390x' in processor(): -+ raise SkipTest("Test fails on s390x, gh#kbandla/dpkt#505") - s = b'\xd0\x00\x3a\x01\x00\x23\x14\x36\x52\x30\xb4\x75\x0e\x46\x83\xc1\xb4\x75\x0e\x46\x83\xc1\x70\x14\x03\x00\x0d\x02\x10\x00\x00\x40\x29\x06\x50\x33\x9e' - ieee = IEEE80211(s, fcs=True) - assert ieee.type == MGMT_TYPE -@@ -769,6 +776,8 @@ def test_action_block_ack_request(): - assert ieee.action.block_ack_request.parameters == parameters - - def test_action_block_ack_response(): -+ if 's390x' in processor(): -+ raise SkipTest("Test fails on s390x, gh#kbandla/dpkt#505") - s = b'\xd0\x00\x3c\x00\xb4\x75\x0e\x46\x83\xc1\x00\x23\x14\x36\x52\x30\xb4\x75\x0e\x46\x83\xc1\xd0\x68\x03\x01\x0d\x00\x00\x02\x10\x88\x13\x9f\xc0\x0b\x75' - ieee = IEEE80211(s, fcs=True) - assert ieee.type == MGMT_TYPE ---- a/dpkt/pcapng.py -+++ b/dpkt/pcapng.py -@@ -8,6 +8,8 @@ from __future__ import absolute_import - - from struct import pack as struct_pack, unpack as struct_unpack - from time import time -+from platform import processor -+from unittest import SkipTest - import sys - - from . import dpkt -@@ -842,6 +844,10 @@ def test_custom_read_write(): - b'\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x41' - b'\x42\x43\x44\x45\x46\x47\x48\x49' - )) -+ -+ if 's390x' in processor(): -+ raise SkipTest("Test fails on s390x, gh#kbandla/dpkt#505") -+ - fobj = BytesIO() - writer = Writer(fobj, shb=shb, idb=idb) - writer.writepkt(epb, ts=1442984653.210838)