From patchwork Tue Jul 24 16:35:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timothy Redaelli X-Patchwork-Id: 948605 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41ZkVh6CgRz9s1R for ; Wed, 25 Jul 2018 02:35:24 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id C05DDD9F; Tue, 24 Jul 2018 16:35:21 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 24122D96 for ; Tue, 24 Jul 2018 16:35:20 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id C162C7C3 for ; Tue, 24 Jul 2018 16:35:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DD0FA402243B for ; Tue, 24 Jul 2018 16:35:18 +0000 (UTC) Received: from localhost.localdomain (dhcp189-71.ntdv.lab.eng.bos.redhat.com [10.19.189.71]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5FFE3111AF38 for ; Tue, 24 Jul 2018 16:35:18 +0000 (UTC) From: Timothy Redaelli To: dev@openvswitch.org Date: Tue, 24 Jul 2018 18:35:13 +0200 Message-Id: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 24 Jul 2018 16:35:18 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 24 Jul 2018 16:35:18 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'tredaelli@redhat.com' RCPT:'' X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH] ovs-tcpdump: Fix incompatibilities with python3 X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Opening a file with 'rw' in Python3 returns an error, moreover using 'rw' in Python2 is wrong too since it opens the file using O_RDONLY and not by using O_RDWR. This commit fixes it by using the low-level os.open function with O_RDWR as suggested by the Linux kernel (tuntap.txt) documentation. This commit fixes also some usual bytes vs string incompatibilities. Tested on Python 2.7.15 and Python 3.6.5 Signed-off-by: Timothy Redaelli --- utilities/ovs-tcpdump.in | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/utilities/ovs-tcpdump.in b/utilities/ovs-tcpdump.in index 91fa14e5a..17b5d48f1 100755 --- a/utilities/ovs-tcpdump.in +++ b/utilities/ovs-tcpdump.in @@ -62,8 +62,8 @@ def _install_tap_linux(tap_name, mtu_value=None): TUNSETIFF = 0x400454CA # This is derived by printf() of TUNSETIFF TUNSETOWNER = TUNSETIFF + 2 - tapdev_fd = open('/dev/net/tun', 'rw') - ifr = struct.pack('16sH', tap_name, IFF_TAP | IFF_NO_PI) + tapdev_fd = os.open('/dev/net/tun', os.O_RDWR) + ifr = struct.pack('16sH', tap_name.encode('utf8'), IFF_TAP | IFF_NO_PI) fcntl.ioctl(tapdev_fd, TUNSETIFF, ifr) fcntl.ioctl(tapdev_fd, TUNSETOWNER, os.getegid()) @@ -457,10 +457,10 @@ def main(): pipes = _doexec(*([dump_cmd, '-i', mirror_interface] + tcpdargs)) try: while pipes.poll() is None: - data = pipes.stdout.readline().strip('\n') + data = pipes.stdout.readline().strip(b'\n') if len(data) == 0: raise KeyboardInterrupt - print(data) + print(data.decode('utf-8')) raise KeyboardInterrupt except KeyboardInterrupt: if pipes.poll() is None: