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 <bhanuprakash.bodire...@intel.com>
Signed-off-by: Aaron Conole <acon...@redhat.com>
---
 utilities/ovs-tcpdump.in | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/utilities/ovs-tcpdump.in b/utilities/ovs-tcpdump.in
index 6718c77..91fa14e 100755
--- a/utilities/ovs-tcpdump.in
+++ b/utilities/ovs-tcpdump.in
@@ -18,6 +18,7 @@ import fcntl
 
 import os
 import pwd
+from random import randint
 import struct
 import subprocess
 import sys
@@ -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):
@@ -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():
@@ -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():
-- 
2.9.5

_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to