From owner-svn-ports-head@freebsd.org Thu Apr 18 18:50:57 2019 Return-Path: Delivered-To: svn-ports-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id AF6821579891; Thu, 18 Apr 2019 18:50:57 +0000 (UTC) (envelope-from lwhsu@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 5536E748DC; Thu, 18 Apr 2019 18:50:57 +0000 (UTC) (envelope-from lwhsu@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 31AE123033; Thu, 18 Apr 2019 18:50:57 +0000 (UTC) (envelope-from lwhsu@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3IIovhP011894; Thu, 18 Apr 2019 18:50:57 GMT (envelope-from lwhsu@FreeBSD.org) Received: (from lwhsu@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3IIouB7011892; Thu, 18 Apr 2019 18:50:56 GMT (envelope-from lwhsu@FreeBSD.org) Message-Id: <201904181850.x3IIouB7011892@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: lwhsu set sender to lwhsu@FreeBSD.org using -f From: Li-Wen Hsu Date: Thu, 18 Apr 2019 18:50:56 +0000 (UTC) To: ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org Subject: svn commit: r499307 - in head/net/scapy: . files X-SVN-Group: ports-head X-SVN-Commit-Author: lwhsu X-SVN-Commit-Paths: in head/net/scapy: . files X-SVN-Commit-Revision: 499307 X-SVN-Commit-Repository: ports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 5536E748DC X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.95 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.95)[-0.954,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-ports-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the ports tree for head List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Apr 2019 18:50:58 -0000 Author: lwhsu Date: Thu Apr 18 18:50:56 2019 New Revision: 499307 URL: https://svnweb.freebsd.org/changeset/ports/499307 Log: Add a patch from upstream which solves the interface name may not end by digit PR: 237305 Obtained from: https://github.com/secdev/scapy/pull/1991 Sponsored by: The FreeBSD Foundation Added: head/net/scapy/files/1991.patch (contents, props changed) Modified: head/net/scapy/Makefile Modified: head/net/scapy/Makefile ============================================================================== --- head/net/scapy/Makefile Thu Apr 18 18:01:40 2019 (r499306) +++ head/net/scapy/Makefile Thu Apr 18 18:50:56 2019 (r499307) @@ -4,6 +4,7 @@ PORTNAME= scapy PORTVERSION= 2.4.2 DISTVERSIONPREFIX= v +PORTREVISION= 1 CATEGORIES= net PKGNAMEPREFIX= ${PYTHON_PKGNAMEPREFIX} Added: head/net/scapy/files/1991.patch ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/net/scapy/files/1991.patch Thu Apr 18 18:50:56 2019 (r499307) @@ -0,0 +1,171 @@ +From 5ff17673eec7fc200a16552e3686015e99d10b5e Mon Sep 17 00:00:00 2001 +From: Pierre LALET +Date: Tue, 16 Apr 2019 16:08:15 +0200 +Subject: [PATCH 1/2] BPF: fix get_working_ifaces() + +It was broken when an interface name did not end by a digit. + +It was also incorrect when an interface name ended by more than one +digit. +--- + scapy/arch/bpf/core.py | 46 ++++++++++++++++++++++++------------------ + test/bpf.uts | 6 ++---- + 2 files changed, 28 insertions(+), 24 deletions(-) + +diff --git scapy/arch/bpf/core.py scapy/arch/bpf/core.py +index cc4732f52..4c9e9470a 100644 +--- scapy/arch/bpf/core.py ++++ scapy/arch/bpf/core.py +@@ -5,22 +5,22 @@ + """ + + from __future__ import absolute_import +-from scapy.config import conf +-from scapy.error import Scapy_Exception, warning +-from scapy.data import ARPHDR_LOOPBACK, ARPHDR_ETHER +-from scapy.arch.common import get_if, compile_filter +-from scapy.consts import LOOPBACK_NAME +- +-from scapy.arch.bpf.consts import BIOCSETF, SIOCGIFFLAGS, BIOCSETIF + ++from ctypes import cdll, cast, pointer ++from ctypes import c_int, c_ulong, c_char_p ++from ctypes.util import find_library ++import fcntl + import os ++import re + import socket +-import fcntl + import struct + +-from ctypes import cdll, cast, pointer +-from ctypes import c_int, c_ulong, c_char_p +-from ctypes.util import find_library ++from scapy.arch.bpf.consts import BIOCSETF, SIOCGIFFLAGS, BIOCSETIF ++from scapy.arch.common import get_if, compile_filter ++from scapy.config import conf ++from scapy.consts import LOOPBACK_NAME ++from scapy.data import ARPHDR_LOOPBACK, ARPHDR_ETHER ++from scapy.error import Scapy_Exception, warning + from scapy.modules.six.moves import range + + +@@ -126,6 +126,9 @@ def get_if_list(): + return interfaces + + ++_IFNUM = re.compile("([0-9]*)([ab]?)$") ++ ++ + def get_working_ifaces(): + """ + Returns an ordered list of interfaces that could be used with BPF. +@@ -156,24 +159,27 @@ def get_working_ifaces(): + if ifflags & 0x1: # IFF_UP + + # Get a BPF handle +- fd, _ = get_dev_bpf() ++ fd = get_dev_bpf()[0] + if fd is None: + raise Scapy_Exception("No /dev/bpf are available !") + + # Check if the interface can be used + try: +- fcntl.ioctl(fd, BIOCSETIF, struct.pack("16s16x", ifname.encode())) # noqa: E501 +- interfaces.append((ifname, int(ifname[-1]))) ++ fcntl.ioctl(fd, BIOCSETIF, struct.pack("16s16x", ++ ifname.encode())) + except IOError: + pass +- +- # Close the file descriptor +- os.close(fd) ++ else: ++ ifnum, ifab = _IFNUM.search(ifname).groups() ++ interfaces.append((ifname, int(ifnum) if ifnum else -1, ifab)) ++ finally: ++ # Close the file descriptor ++ os.close(fd) + + # Sort to mimic pcap_findalldevs() order +- interfaces.sort(key=lambda elt: elt[1]) ++ interfaces.sort(key=lambda elt: (elt[1], elt[2], elt[0])) + +- return interfaces ++ return [iface[0] for iface in interfaces] + + + def get_working_if(): +@@ -183,4 +189,4 @@ def get_working_if(): + if not ifaces: + # A better interface will be selected later using the routing table + return LOOPBACK_NAME +- return ifaces[0][0] ++ return ifaces[0] +diff --git test/bpf.uts test/bpf.uts +index 19e06bb14..45d36fd83 100644 +--- test/bpf.uts ++++ test/bpf.uts +@@ -47,12 +47,10 @@ len(iflist) > 0 + = Get working network interfaces + ~ needs_root + +-from scapy.arch.bpf.core import get_working_ifaces ++from scapy.arch.bpf.core import get_working_if, get_working_ifaces + ifworking = get_working_ifaces() + assert len(ifworking) +- +-from scapy.arch.bpf.core import get_working_if +-assert len(ifworking) and get_working_if() == ifworking[0][0] ++assert get_working_if() == ifworking[0] + + + = Misc functions + +From afa5776ecf83f7a427fc1af763005fe249f450f9 Mon Sep 17 00:00:00 2001 +From: Pierre LALET +Date: Wed, 17 Apr 2019 10:22:16 +0200 +Subject: [PATCH 2/2] BPF: test get_working_ifaces() + +--- + test/bpf.uts | 27 +++++++++++++++++++++++++++ + 1 file changed, 27 insertions(+) + +diff --git test/bpf.uts test/bpf.uts +index 45d36fd83..23022530e 100644 +--- test/bpf.uts ++++ test/bpf.uts +@@ -53,6 +53,33 @@ assert len(ifworking) + assert get_working_if() == ifworking[0] + + ++= Get working network interfaces order ++ ++import mock ++from scapy.arch.bpf.core import get_working_ifaces ++ ++@mock.patch("scapy.arch.bpf.core.os.close") ++@mock.patch("scapy.arch.bpf.core.fcntl.ioctl") ++@mock.patch("scapy.arch.bpf.core.get_dev_bpf") ++@mock.patch("scapy.arch.bpf.core.get_if") ++@mock.patch("scapy.arch.bpf.core.get_if_list") ++@mock.patch("scapy.arch.bpf.core.os.getuid") ++def test_get_working_ifaces(mock_getuid, mock_get_if_list, mock_get_if, ++ mock_get_dev_bpf, mock_ioctl, mock_close): ++ mock_getuid.return_value = 0 ++ mock_get_if_list.return_value = ['igb0', 'em0', 'msk0', 'epair0a', 'igb1', ++ 'vlan20', 'igb10', 'igb2'] ++ mock_get_if.return_value = (b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' ++ b'\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00' ++ b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') ++ mock_get_dev_bpf.return_value = (31337,) ++ mock_ioctl.return_value = 0 ++ mock_close.return_value = 0 ++ return get_working_ifaces() ++ ++assert test_get_working_ifaces() == ['em0', 'igb0', 'msk0', 'epair0a', 'igb1', ++ 'igb2', 'igb10', 'vlan20'] ++ + = Misc functions + ~ needs_root +