]> git.proxmox.com Git - mirror_ovs.git/commitdiff
ovs-tcpdump: Fallback to read /proc/net/dev on Linux
authorTimothy Redaelli <tredaelli@redhat.com>
Mon, 13 Jan 2020 16:47:03 +0000 (17:47 +0100)
committerBen Pfaff <blp@ovn.org>
Mon, 13 Jan 2020 17:41:54 +0000 (09:41 -0800)
Currently, ovs-tcpdump uses python3-netifaces in order to get the list of
the network interfaces, but python3-netifaces may not be installed nor
available on some distributions (for example on RHEL7).

This commit adds, only for Linux, an alternative way (that is only used
when netifaces is not available) to read the list of the network interfaces
by reading "/proc/net/dev".

Signed-off-by: Timothy Redaelli <tredaelli@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
utilities/ovs-tcpdump.in

index 0fa5dc418c7e839e60b1d30375dc11d63b9e4279..5ec02383c0ce5c8dbcbf8742f413c8c5ffb83a8e 100755 (executable)
@@ -24,7 +24,21 @@ import subprocess
 import sys
 import time
 
-import netifaces
+try:
+    from netifaces import interfaces
+except ImportError:
+    if sys.platform in ['linux', 'linux2']:
+        def interfaces():
+            devices = []
+            with open("/proc/net/dev", "r") as f_netdev:
+                for line in f_netdev:
+                    if ":" not in line:
+                        continue
+                    devices.append(line.split(":")[0].strip())
+            return devices
+    else:
+        print("ERROR: Please install netifaces Python library.")
+        sys.exit(1)
 
 try:
     from ovs.db import idl
@@ -438,11 +452,11 @@ def main():
             mirror_interface = _make_mirror_name[sys.platform](interface)
 
     if sys.platform in _make_taps and \
-       mirror_interface not in netifaces.interfaces():
+       mirror_interface not in interfaces():
         _make_taps[sys.platform](mirror_interface,
                                  ovsdb.interface_mtu(interface))
 
-    if mirror_interface not in netifaces.interfaces():
+    if mirror_interface not in interfaces():
         print("ERROR: Please create an interface called `%s`" %
               mirror_interface)
         print("See your OS guide for how to do this.")