Skip to content

Commit

Permalink
ovs-tcpdump: handle large interface names on linux
Browse files Browse the repository at this point in the history
Linux has a fixed size interface name, which will not change.  This means
that attempts to dump interfaces whose names are larger than the max size
will result in an error making the tap device.

This commit brings a new function.  When the generated name would be too
large, use a random number prefixed by 'ovsmi' instead.

Reported-by: Bhanuprakash Bodireddy <[email protected]>
Signed-off-by: Aaron Conole <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
apconole authored and blp committed Nov 13, 2017
1 parent 9e84893 commit b4027b1
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion utilities/ovs-tcpdump.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import fcntl

import os
import pwd
from random import randint
import struct
import subprocess
import sys
Expand All @@ -39,6 +40,8 @@ except Exception:

tapdev_fd = None
_make_taps = {}
_make_mirror_name = {}
IFNAMSIZ_LINUX = 15 # this is the max name size, excluding the null byte.


def _doexec(*args, **kwargs):
Expand Down Expand Up @@ -76,8 +79,16 @@ def _install_tap_linux(tap_name, mtu_value=None):
pipe.wait()


def _make_linux_mirror_name(interface_name):
if len(interface_name) > IFNAMSIZ_LINUX - 2:
return "ovsmi%06d" % randint(1, 999999)
return "mi%s" % interface_name


_make_taps['linux'] = _install_tap_linux
_make_taps['linux2'] = _install_tap_linux
_make_mirror_name['linux'] = _make_linux_mirror_name
_make_mirror_name['linux2'] = _make_linux_mirror_name


def username():
Expand Down Expand Up @@ -406,7 +417,10 @@ def main():
print("TCPDUMP Args: %s" % ' '.join(tcpdargs))

ovsdb = OVSDB(db_sock)
mirror_interface = mirror_interface or "mi%s" % interface
if mirror_interface is None:
mirror_interface = "mi%s" % interface
if sys.platform in _make_mirror_name:
mirror_interface = _make_mirror_name[sys.platform](interface)

if sys.platform in _make_taps and \
mirror_interface not in netifaces.interfaces():
Expand Down

0 comments on commit b4027b1

Please sign in to comment.