Skip to content

Commit

Permalink
ovs-tcpdump: Fix incompatibilities with python3
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
drizzt authored and blp committed Jul 24, 2018
1 parent 227abb7 commit 793bdb6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions utilities/ovs-tcpdump.in
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 793bdb6

Please sign in to comment.